/*
 * Exploder
 * 
 * Tero Pyylampi (218437), Jussi Tuurinkoski (211594)
 *
 * A handle for processing touch events received
 */


#ifndef GAMETOUCHHANDLE_H
#define GAMETOUCHHANDLE_H

#include "cocos2d.h"
#include "Box2D/Box2D.h"

class GameCamera;

enum TouchType {
	// not currently doing anything
	TOUCH_NONE,
	// moving camera with single finger 
	TOUCH_CAMERA_SINGLE,
	// moving or zooming camera
	TOUCH_CAMERA_MULTI,
	// moving box2d object
	TOUCH_PHYSICS_OBJECT
};

class GameTouchHandle {
public:
	// default constructor
	GameTouchHandle( GameCamera *gameCamera, b2Body *groundBody );
	// default destructor
	~GameTouchHandle();

	// start moving camera with a single finger
	void startMovingCamera( cocos2d::CCTouch *touch, cocos2d::CCLayer *layer );
	// start moving camera / zooming event
	void startCameraTouch( cocos2d::CCTouch *touch, cocos2d::CCLayer *layer );
	// start moving an object
	void startObjectTouch( cocos2d::CCTouch *touch, cocos2d::CCLayer *layer, b2Body *body, b2World *world );

	// convert this event to the multi camera slave
	void resetToMultiCameraSlave();

	// update this touch handle
	void update( cocos2d::CCTouch *touch, cocos2d::CCLayer *layer );
	// reset this touch handle
	void reset();

	// release current object touch
	void releaseObject();
	// set another handle
	void setAnotherTouchHandle( GameTouchHandle *anotherHandle );
	// get touch
	cocos2d::CCTouch *getTouch();
	// get current mode
	TouchType getCurrentType();
	// get hit body
	b2Body *getHitBody();

	// whether the treshold has been reached
	bool tresholdReached();
	// get starting pos in world coords
	b2Vec2 getStartingPosInWorldCoords();

	// set invalid bomb position
	void setInvalidBombPosition( bool state );
	// get invalid bomb position
	bool getInvalidBombPosition();

private:
	// pointer to the game camera
	GameCamera *mGameCamera;

	// current on-going touch
	cocos2d::CCTouch *mTouch;
	// touch type
	TouchType mTouchType;

	// pointer to the another touch handle (used on two finger camera events)
	GameTouchHandle *mAnotherHandle;

	// touch starting position
	cocos2d::CCPoint mStartingPos;
	// treshold clutch
	bool mTresholdReached;
	const float mCameraTreshold;
	// zoom direction, false = zoom out, true = zoom in
	bool mZoomDirection;

	// for saving mouse joints
	b2MouseJoint *mMouseJoint;
	b2Body *mHitBody;
	b2Body *mGroundBody;

	// calculates the distance between two points
	float distanceBetweenPoints( cocos2d::CCPoint &p1, cocos2d::CCPoint &p2 );

	// flag variable for saving information about bombs
	bool mInvalidBombPosition;
};

#endif